<template>
 <div>

    <el-table border :data="records">
      <el-table-column label="序号" type="index" width="80"></el-table-column>
      <el-table-column label="名称"  prop="skuName"></el-table-column>
      <el-table-column label="描述" prop="skuDesc"></el-table-column>
      <el-table-column label="默认图片" width="110">
        <template scope="{row}">
            <img :src="row.skuDefaultImg" alt="" style="width: 80px;height: 80px;">
        </template>
      </el-table-column>
      <el-table-column label="重量" width="80" prop="weight"></el-table-column>
      <el-table-column label="价格" width="80" prop="price"></el-table-column>
      <el-table-column label="操作">
        <template scope="{row}">
            <el-button @click="down(row)"  v-if="row.isSale" type="info" icon="el-icon-top" size="mini"></el-button>
            <el-button @click="up(row)" v-else type="success" icon="el-icon-bottom" size="mini"></el-button>
            <el-button @click="edit" type="primary" icon="el-icon-edit" size="mini"></el-button>
            <el-button @click="skuById(row)" type="info" icon="el-icon-info" size="mini"></el-button>
            <el-button type="danger" icon="el-icon-delete" size="mini"></el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination @current-change="getSkuList" @size-change="sizeChange" style="text-align: center;" :total="total" :current-page="page" :page-sizes="[3,5,9]" :page-size="limit"  layout="prev,pager,next,jumper,->,sizes,total"></el-pagination>
    
    
    <el-drawer :visible.sync="drawer" direction="rtl" :show-close="false" size="50%" :before-close="handleClose">
      <el-row>
        <el-col :span="5">名称</el-col>
        <el-col :span="16">{{ skuList.skuName }}</el-col>
      </el-row>
      <el-row>
        <el-col :span="5">描述</el-col>
        <el-col :span="16">{{ skuList.skuDesc }}</el-col>
      </el-row>
      <el-row>
        <el-col :span="5">价格</el-col>
        <el-col :span="16">{{ skuList.price }}</el-col>
      </el-row>
      <el-row>
        <el-col :span="5">平台属性</el-col>
        <el-col :span="16">
            <el-tag type="success" v-for="attr in skuList.skuAttrValueList" :key="attr.attrId" style="margin: 0px 10px;">{{`${attr.attrId}-${attr.valueId}`}}</el-tag>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="5">商品图片</el-col>
        <el-col :span="16">
            <el-carousel height="150px">
              <el-carousel-item v-for="item in skuList.skuImageList" :key="item.id">
                <img :src="item.imgUrl" alt="">
              </el-carousel-item>
            </el-carousel>
        </el-col>
      </el-row>
    </el-drawer>

 </div>
</template>

<script>
export default {
    name: 'sku',
    data(){
        return {
            // 总数据量
            total:0,
            page:1,
            limit:3,
            // 每一页展示的数据
            records:[],
            skuList:{},
            drawer:false,
           }
    },
    mounted(){
        this.getSkuList()
    },
    methods:{
        async getSkuList(pages=1){
            this.page=pages;
            let {limit,page}=this;
            let result=await this.$tradeAPI.sku.reqSkuList(page,limit);
            if(result.code=200){
                this.records=result.data.records;
                this.total=result.data.total;
            }
        },

        sizeChange(limit){
            this.limit=limit;
            this.getSkuList()
        },

        async up(row){
            let result=await this.$tradeAPI.sku.reqSale(row.id);
            if(result.code==200){
                this.$message({type:"success",message:"上架成功"});
                row.isSale=1;
            }
        },

        async down(row){
            let result=await this.$tradeAPI.sku.reqCancel(row.id);
            if(result.code==200){
                this.$message({type:"success",message:"下架成功"});
                row.isSale=0;
            }
        },

        edit(){
            this.$message('正在开发中...')
        },

        async skuById(row){
            let result=await this.$tradeAPI.sku.reqSkuById(row.id);
            if(result.code==200){
                this.skuList=result.data;
                this.drawer=true
            }
        },

        handleClose(){
            this.drawer=false
        }


    }
}
</script>
<!-- class="el-carousel__indicator el-carousel__indicator--horizontal" -->
<style scoped>
>>>.el-row .el-col-5{
    text-align: right;
    font-size: 18px;
    font-weight: bold;
}

>>>.el-col{
    margin: 10px;
}
>>>.el-carousel__button{
    width: 10px;
    height: 10px;
    background: red;
    border-radius: 50%;
}
</style>

<style>
  .el-carousel__item h3 {
    color: #475669;
    font-size: 14px;
    opacity: 0.75;
    line-height: 150px;
    margin: 0;
  }

  .el-carousel__item:nth-child(2n) {
     background-color: #99a9bf;
  }
  
  .el-carousel__item:nth-child(2n+1) {
     background-color: #d3dce6;
  }
</style>